﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GameEngine.SceneGraph;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;



namespace Redland2
{
    class Enemy : Player
    {
        #region members

        private const float ENEMY_MOVE_SPEED = 2.0F;
        private const int ENEMY_IDLE_FRAME = 4;
        private bool _active = true;

        #endregion members

        #region properties
        public bool Active
        {
            get { return _active; }
            set { _active = value; }
        }
        #endregion properties

        #region constructors

        public Enemy(GameScene inputScene, int inputIndex) : base(inputScene, inputIndex, false)
        {
            base.Texture = GameScene.Current.Content.Load<Texture2D>("Enemy");
            this.type = "enemy";
            SetupPlayer();
        }

        private void SetupPlayer()
        {
            this.Layer = 0.9F;
            this.AnimationData.RowsColumns = new Vector2(4, 4);
            this.AnimationData.BeginEndFrames = new Vector2(0, 15);
            this.AnimationData.Frame = 4;
            this.AnimationData.AnimationSpeed = 0.035f;
            this.SetOffset(GameEngine.Drawables.Anchor.Center);
        }

        #endregion constructors

        #region methods

        public override void startWalking()
        {
            this.AnimationData.Animated = true;
        }
        public override void stopWalking(int duration)
        {
            this.AnimationData.Animated = false;
            this.AnimationData.Frame = ENEMY_IDLE_FRAME;
        }

        public override void Update(GameTime gameTime)
        {
            this.TargetPos = scene._entities.ElementAt(0).Position;

            if ((this.TargetPos - this.Position).Length() > 100 && _active)
            {
                this.moveForward();
                this.startWalking();
                this.Fire();
            }
            else
                this.stopWalking(0);

            base.Update(gameTime);
        }

        public override void Kill()
        {
            scene.intLevel++;
            base.Kill();
        }

        #endregion methods
    }
}
